import TJavaLib.TList;
import TJavaLib.TPoint;

public class TNetwork {
	private TList net;
	private TSimulator simulator;
	private double depW, depH;
	
	public TNetwork(TSimulator sim) {
		net = new TList();
		depW = 800;
		depH = 600;
		simulator = sim;
	}

	public int len() { 
		return net.len(); 
	}
	
	public TList getNetwork() { 
		return net; 
	}
	
	public TSimulator getSimulator() {
		return simulator;
	}
	
	public TSensor newSensor() {
		TSensor sensor = new TSensor(simulator);
		net.enList(sensor);
		return sensor;
	}
	
	public TGateway newGateway() {
		TGateway gateway = new TGateway(simulator);
		net.enList(gateway);
		return gateway;
	}
	
	public void setDepW(double depW) { 
		this.depW = depW; 
	}
	
	public double getDepW() { 
		return depW; 
	}
	
	public void setDepH(double depH) { 
		this.depH = depH; 
	}
	
	public double getDepH() { 
		return depH; 
	}
	
	//----------------------------Simulator Stuff----------------------------------
	public void scanJob() {}
	
	public TNode findNode(String addr) {
		TNode rs = null;
		for (int i=0; i<net.len(); i++) {
			TNode node = (TNode)net.get(i);
			if (addr.equalsIgnoreCase(node.getAddr())) {
				rs = node;
				break;
			}
		}
		return rs;
	}
	
	public TNode send(String desAddr) {
		return findNode(desAddr);
	}
	
	public TList get1HopNeighbors(TNode node) {
		TList nbs = new TList();
		for (int i=0; i<net.len(); i++) {
			TNode n = (TNode)net.get(i);
			if (n != node) {
				if (TPoint.dist(n.getLoc(), node.getLoc()) <= n.getRadio().getTX())
					nbs.enList(n);
			}
		}
		return nbs;
	}
}
